<template>
<el-select v-model="ruleForm[field]" :placeholder="tips" clearable @change="changeEvt">
    <el-option v-for="item in options" :key="item.value" :label="item.title" :value="item.id">
    </el-option>
</el-select>
</template>

<script>
import {
    getPickerApi
} from '@/api/system/dictionary/dictionary.js'

export default {
    name: "PickerView",
    data() {
        return {
            options: []
        };
    },
    props: {
        ruleForm: Object,
        field: {
            type: String,
            default: ""
        },
        type: {
            type: String,
            default: ""
        },
        tips: {
            type: String,
            default: "请选择"
        },
        filter: {
            type: Object,
            default: function () {
                return {};
            }
        }
    },
    watch: {
        type: {
            immediate: true,
            handler(value) {
                let _this = this;
                let options = {
                    type: value
                };
                options.filter = this.filter;

                getPickerApi(options).then(res => {
                    _this.options = res.data.list;
                })
            },
        },
    },
    methods: {
        changeEvt() {
            this.$emit("change", this.ruleForm[this.field])
        }
    }
}
</script>
